<?php
function getPageNavigation($page, $n,$c,$factor=2) {
    $t =ceil($n/$c); //total page count.    
	if ($t<=1)return;

	$url=explode("?",$_SERVER["REQUEST_URI"],2);
	parse_str($url[1],$parse);
	$parse["p"]=$page;
	$url=$url[0]."?";
	foreach($parse as $key=>$value)$url.=$key."=".$value."&";
	$url=substr($url,0,-1);

	$p = $page; //page nomber of current.
    $f = $factor; //factor of paginate.
    $o = $f * 2; //offset of paginate.
    $l = ''; //left.
    $r = ''; //right.
    $e = '…'; //ellipsis.
    $s_s = '<a href="'.$url; //separator start
	$s_e = '</a>'; //separator end

    if ($p-$o <= $f) {
        for ($i=1; $i<$p; $i++)        
            $l .=$s_s.'&p='.$i.'">'.$i. $s_e;
    } else {
        for ($i=1; $i<=$f; $i++)        
            $l .= $s_s.'&p='.$i.'">'.$i. $s_e;
        $l .= $e;
        for ($i=($p-$f); $i<$p; $i++)        
            $l .= $s_s.'&p='.$i.'">'.$i. $s_e;
    }
    
    if ($t-$p <= $o+1) {
        for ($i=$p+1; $i<=$t; $i++)
            $r .= $s_s.'&p='.$i.'">'.$i. $s_e;;
    } else {
        for ($i=$p+1; $i<=$p+$o; $i++)        
            $r .=$s_s.'&p='.$i.'">'.$i. $s_e;;
        $r .= $e;
    }
     return $l.'<span class="current">'.$p.'</span> '. $r;
    
}
function gettaobaoPageNavigation($page, $n,$c,$factor=2) {
    $t =ceil($n/$c); //total page count.    
	if ($t<=1)return;
	$p = $page; //page nomber of current.
    $f = $factor; //factor of paginate.
    $o = $f * 2; //offset of paginate.
    $l = ''; //left.
    $r = ''; //right.
    $e = '…'; //ellipsis.
    $s_s = '<a href="javascript:;" onclick="taobao_items_onsale_get('; //separator start
	$s_e = '</a>'; //separator end

    if ($p-$o <= $f) {
        for ($i=1; $i<$p; $i++)        
            $l .=$s_s.$i.')">'.$i. $s_e;
    } else {
        for ($i=1; $i<=$f; $i++)        
            $l .= $s_s.$i.')">'.$i. $s_e;
        $l .= $e;
        for ($i=($p-$f); $i<$p; $i++)        
            $l .= $s_s.$i.')">'.$i. $s_e;
    }
    
    if ($t-$p <= $o+1) {
        for ($i=$p+1; $i<=$t; $i++)
            $r .= $s_s.$i.')">'.$i. $s_e;;
    } else {
        for ($i=$p+1; $i<=$p+$o; $i++)        
            $r .=$s_s.$i.')">'.$i. $s_e;;
        $r .= $e;
    }
     return $l.'<span class="current">'.$p.'</span> '. $r;
}
function getBuyerPageNavigation($page, $n,$c,$factor=2) {
    $t =ceil($n/$c); //total page count.    
	if ($t<=1)return;

	$url=explode("?",$_SERVER["REQUEST_URI"],2);
	parse_str($url[1],$parse);
	$parse["p"]=$page;
	$url=$url[0]."?";
	foreach($parse as $key=>$value)$url.=$key."=".$value."&";
	$url=substr($url,0,-1);

	$p = $page; //page nomber of current.
    $f = $factor; //factor of paginate.
    $o = $f * 2; //offset of paginate.
    $l = ''; //left.
    $r = ''; //right.
    $e = '…'; //ellipsis.
    $s_s = '<a href='.$url; //separator start
	$s_e = '</a>'; //separator end

    if ($p-$o <= $f) {
        for ($i=1; $i<$p; $i++)        
            $l .=$s_s.'&p='.$i.'>'.$i. $s_e;
    } else {
        for ($i=1; $i<=$f; $i++)        
            $l .= $s_s.'&p='.$i.'>'.$i. $s_e;
        $l .= '<span class="page-break">'.$e.'</span>';
        for ($i=($p-$f); $i<$p; $i++)        
            $l .= $s_s.'&p='.$i.'>'.$i. $s_e;
    }
    
    if ($t-$p <= $o+1) {
        for ($i=$p+1; $i<=$t; $i++)
            $r .= $s_s.'&p='.$i.'>'.$i. $s_e;;
    } else {
        for ($i=$p+1; $i<=$p+$o; $i++)        
            $r .=$s_s.'&p='.$i.'>'.$i. $s_e;;
        $r .= '<span class="page-break">'.$e.'</span>';
    }
	if ($page==1){$f_s='<span class="page-start"><b class="icon"></b>上一页</span>';}
		else{$f_s='<a class="page-prev" href="'.$url.'&p='.($page-1).'"><b class="icon"></b>上一页</a>';}
	if ($page==$t){$f_e='<span class="page-end">下一页<b class="icon"></b></span>';}
		else{$f_e='<a class="page-next" href="'.$url.'&p='.($page+1).'">下一页<b class="icon"></b></a>';}

     return $f_s.$l.'<span class="page-cur">'.$p.'</span> '. $r.$f_e;
}
?>
